$(document).ready(function()
{
	var form=$('#Form_Password');
	var button=$('#Submit_Password');
	
	var oldPassword=$('#OldPassword');
	var newPassword=$('#NewPassword');
	var confirmPassword=$('#ConfirmPassword');
	
	var ac=$('#AlertContainer');
	var ace_oldPassword=$('#AlertContainer_Error_OldPassword');
	var ace_newPassword=$('#AlertContainer_Error_NewPassword');
	var ace_confirmPassword=$('#AlertContainer_Error_ConfirmPassword');
		
	oldPassword.keyup(function()
	{
		if(oldPassword.val()=='')
		{
			ace_oldPassword.html('请填写旧密码');
			ace_oldPassword.fadeIn();
		}
		else
		{
			ace_oldPassword.fadeOut();
		}
	});
	
	newPassword.keyup(function()
	{
		if(newPassword.val()=='')
		{
			ace_newPassword.html('请填写新密码');
			ace_newPassword.fadeIn();
		}
		else
		{
			ace_newPassword.fadeOut();
		}
	});
	
	confirmPassword.keyup(function()
	{
		if(confirmPassword.val()=='')
		{
			ace_confirmPassword.html('请确认新密码');
			ace_confirmPassword.fadeIn();
		}
		else
		{
			if(confirmPassword.val()!=newPassword.val())
			{
				ace_confirmPassword.html('两次密码输入不一致，请重新填写');	
				ace_confirmPassword.fadeIn();
			}		
			else
			{
				ace_confirmPassword.fadeOut();
			}
		}
	});		
	
	form.submit(function()
	{
		if(oldPassword.val()=='')
		{
			ace_oldPassword.html('请填写旧密码');
			ace_oldPassword.fadeIn();
			oldPassword.focus();					
			return false;
		}
		
		if(newPassword.val()=='')
		{
			ace_newPassword.html('请填写新密码');
			ace_newPassword.fadeIn();
			newPassword.focus();						
			return false;
		}
		
		if(confirmPassword.val()=='')
		{
			ace_confirmPassword.html('请确认新密码');
			ace_confirmPassword.fadeIn();			
			confirmPassword.focus();					
			return false;
		}		
		else
		{
			if(confirmPassword.val()!=newPassword.val())
			{
				ace_confirmPassword.html('两次密码输入不一致，请重新填写');
				ace_confirmPassword.fadeIn();
				confirmPassword.select();						
				return false;				
			}
		}
		
		button.attr('disabled',true);
		ac.html('正在处理中，请稍候..');
		ac.css('color','black');		
		ac.show();
		
		setTimeout(function()
		{
			$.post(form.action,{OldPassword:oldPassword.val(),NewPassword:newPassword.val(),ConfirmPassword:confirmPassword.val()},function($data)
			{
				switch($data)
				{
					case 'PasswordWrong':
						ace_oldPassword.html('密码输入错误，请重新输入');
						ace_oldPassword.fadeIn();
						oldPassword.select();
						button.attr('disabled',false);
						ac.hide();					
					break;
					
					case 'Success':
						ac.html('<img src="images/reg_ico03.gif" style="margin-right:10px;;">密码修改成功');
						ac.css('color','red');
						ac.css('font-size','16px');
						ac.css('font-weight','bold');
						ac.fadeIn();
						oldPassword.val('');
						newPassword.val('');
						confirmPassword.val('');					
						button.attr('disabled',false);						
					break;
					
					default:
						document.write($data);				
				}
			});							
		},1000);
		
		return false;
	});	
});